package com.miniot.base.controller;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.miniot.base.entity.TypeOne;
import com.miniot.base.service.TypeOneService;
import com.miniot.base.vo.TypeOnePageVO;
import com.miniot.base.vo.TypeOneQueryVO;
import com.miniot.base.vo.TypeOneVO;
import com.miniot.business.base.BaseController;
import com.miniot.business.base.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 一级类型表
 *
 * @author zzq
 * @date 2023-10-17 11:16:02
 */
@RestController
@AllArgsConstructor
@RequestMapping("/typeone" )
@Api(value = "一级类型表(后台)", tags = "一级类型表-后台接口")

public class TypeOneController extends BaseController {

    private final TypeOneService typeOneService;

    /**
    * 分页查询
    * @param currentPage 当前页数
    * @param pageSize 每页数据量
    * @param typeOneName 查询条件
    * @return 查询结果
    */
    @GetMapping("/listPage")
    @ApiOperation(value = "分页查询", notes = "传入分页信息与查询条件")
    public R<Page<TypeOnePageVO>> listTypeOnePage(
            @ApiParam(value = "当前页数", required = true, defaultValue = "1") @RequestParam Long currentPage,
            @ApiParam(value = "每页数据量", required = true, defaultValue = "10") @RequestParam Long pageSize,
            @ApiParam(value = "查询条件") String typeOneName) {
        Page<TypeOne> page = new Page<TypeOne>(currentPage, pageSize);
        Page<TypeOnePageVO> pageData = typeOneService.pageChild(page,typeOneName);
        return R.success(pageData,"分页信息查询成功");
    }


    /**
    * 通过id查询一级类型表
    * @param id id
    * @return Result
    */
    @GetMapping("/getById")
    @ApiOperation(value = "通过id查询一级类型表", notes = "传入id")
    public R getTypeOneById(@ApiParam(value = "id", required = true) @RequestParam("id") Long id) {
        return R.success(typeOneService.getById(id));
    }

    /**
    * 新增一级类型表
    * @param typeOne 一级类型表
    * @return Result
    */
    @PostMapping("/save")
    @ApiOperation(value = "新增一级类型表", notes = "传入TypeOne数据")
    public R<Boolean> save(@RequestBody TypeOneVO typeOne) {
        TypeOne typeOne1 = new TypeOne();
        BeanUtil.copyProperties(typeOne, typeOne1);
        Assert.isTrue(typeOneService.save(typeOne1), "操作失败");
        return R.success(true,"新增成功");
    }

    /**
    * 修改一级类型表
    * @param typeOne 一级类型表
    * @return Result
    */
    @PostMapping("/updateById")
    @ApiOperation(value = "修改一级类型表", notes = "传入TypeOne数据")
    public R<Boolean> updateById(@RequestBody TypeOne typeOne) {
        Assert.isTrue(typeOneService.updateById(typeOne), "修改失败");
        return R.success(true,"修改成功");
    }

    /**
    * 通过id删除一级类型表
    * @param id id
    * @return Result
    */
    @GetMapping("/deleteById")
    @ApiOperation(value = "通过id删除一级类型表", notes = "传入id")
    public R<Boolean> deleteById(
            @ApiParam(value = "id", required = true) @RequestParam("id") Long id) {
        Assert.isTrue(typeOneService.removeTypeOneById(id), "操作失败");
        return R.success(true,"删除成功");
    }
}